package com.example.deertrip.database;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import com.example.deertrip.MainActivity;
import com.example.deertrip.R;
import com.example.deertrip.bean.Tb_AdminInfo;
import com.example.deertrip.bean.Tb_UserInfo;
import com.example.deertrip.database.DBOperate;
import com.example.deertrip.bean.Test;

import java.io.ByteArrayOutputStream;

public class DBHleper extends SQLiteOpenHelper {
    private  static final String DATEBASE_NAME="deertrip.db";
    private  static int DATABASE_VERSION=1;
    private static DBHleper dbHelper;
    public  DBHleper(Context context){
        super(context,DATEBASE_NAME,null,DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("create table Tb_HotelInfo(HotelName primary key,"+"HotelAddress char(10),HotelTel integer(20),HotelImage BLOB,HotelScore char(10))");
        sqLiteDatabase.execSQL("create table moment(_id integer primary key autoincrement,"+"username char(10),good integer,image BLOB,content char(20))");
        sqLiteDatabase.execSQL("create table Tb_HotelReserve(HotelOrderNum integer primary key autoincrement,"+"HotelName char(10),RoomNumber integer(10),HotelOrderPrice integer(20),RoomType char(10),UserName char(10),CheckinDate char(10),CheckoutDate char(10))");
        sqLiteDatabase.execSQL("create table Flight(FlightNumber integer primary key,"+"TakeoffTime char(10),SeatClass char(10),TicketPrice integer,P2 integer,P3 integer,CompanyName char(10),LandingTime char(10),TotalHour char(10),FlightForm char(10),FlightTo char(10),CompanyImage BLOB)");
        sqLiteDatabase.execSQL("create table Tb_UserInfo(UserName primary key,"+"UserPassword varchar(10),UserTel varchar(11),UserAddress varchar(20),WxBalance varchar(5),YhkBalance varchar(5),ZfbBalance varchar(5))");
        sqLiteDatabase.execSQL("create table Tb_AdminInfo(AdminName primary key,"+"AdminPassword char(10))");
        //管理员数据库
        // Tb_AdminInfo adminInfo1=new Tb_AdminInfo("jxy","jxy");
        sqLiteDatabase.execSQL("insert into Tb_AdminInfo(AdminName,AdminPassWord) values(?,?) ",new Object[]{"admin","admin"});

        //用户数据库
        //Tb_UserInfo userInfo1=new Tb_UserInfo("wyx","wyx","18876947736","HK");
        sqLiteDatabase.execSQL("insert into Tb_UserInfo(UserName,UserPassword,UserTel,UserAddress,WxBalance,YhkBalance,ZfbBalance) values(?,?,?,?,?,?,?)",new Object[]{"超级小公组","123456","1887947736","辽宁省大连市大连海事大学","1000","100","20"});
    }


    public static synchronized  DBHleper getInstance(Context context) {

        if (dbHelper == null) { //单例模式
            dbHelper = new DBHleper(context);
        }
        return dbHelper;
    }


    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS test");
        onCreate(sqLiteDatabase);
    }

    @Override
    public void onOpen(SQLiteDatabase sqLiteDatabase){
        super.onOpen(sqLiteDatabase);
    }



}
